package com.pengcheng.taskapplication.mvp.view.activity;


import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.contants.ConstantValue;
import com.pengcheng.taskapplication.model.CarSignModel;
import com.pengcheng.taskapplication.model.UrlItemModel;
import com.pengcheng.taskapplication.mvp.presenter.UserPresenter;
import com.pengcheng.taskapplication.net.IView;
import com.pengcheng.taskapplication.util.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class ActivityBiaoShi extends BaseActivity implements IView {

    @BindView(R.id.tv_center_title)
    TextView tv_center_title;

    @BindView(R.id.tv_car_num)
    TextView tv_car_num;

    private CarSignModel carSignModel;

    @BindView(R.id.tv_car_e_card)
    TextView tv_car_e_card;

    private UserPresenter userPresenter;

    @Override
    protected int layoutResID() {
        return R.layout.activity_biaoshi_layout;
    }

    @Override
    protected void initData() {
        tv_center_title.setText("标识信息");
        userPresenter = new UserPresenter(this);
        carSignModel= (CarSignModel) getIntent().getSerializableExtra("model");
        if(carSignModel!=null){
            tv_car_num.setText(carSignModel.getPlate_no());
            tv_car_e_card.setText(carSignModel.getEcard_code());

        }

    }

    @OnClick({R.id.img_back,R.id.ll_one,R.id.ll_two,R.id.ll_three})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                this.finish();
                break;
            case R.id.ll_one:
                if(carSignModel!=null){
                    getNianJianUrl(carSignModel.getVehicle_id());
                }

                break;
            case R.id.ll_two:
                if(carSignModel!=null){
                    getXSZUrl(carSignModel.getVehicle_id());
                }

                break;
            case R.id.ll_three:
                    ToastUtils.showShortToast("暂未开通");
                break;
        }
    }



    public void getNianJianUrl(String vehicleId){
        userPresenter.getNianJianUrl(vehicleId, ConstantValue.RequestKey.getNianJianUrl);
    }

    public void getXSZUrl(String vehicleId){
        userPresenter.getXSZUrl(vehicleId,ConstantValue.RequestKey.getxszUrl);
    }

    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        if(actionType.equals(ConstantValue.RequestKey.getNianJianUrl)){
            UrlItemModel urlItemModel=(UrlItemModel)data;
            Intent intent =new Intent(context,Html5Activity.class);
            intent.putExtra("url",urlItemModel.getUrl());
            intent.putExtra("title","检验标识电子凭证");
            startActivity(intent);
        }

        if(actionType.equals(ConstantValue.RequestKey.getxszUrl)){
            UrlItemModel urlItemModel=(UrlItemModel)data;
            Intent intent =new Intent(context,Html5Activity.class);
            intent.putExtra("url",urlItemModel.getUrl());
            intent.putExtra("title","电子行驶证");
            startActivity(intent);
        }
    }

    @Override
    public void onFailed(String code, String msg) {
        ToastUtils.showShortToast(msg);
    }
}
